package com.ssy.lingxi.scheduler.entity;

import com.ssy.lingxi.scheduler.handler.convert.JpaJsonToLongListConverter;
import com.ssy.lingxi.scheduler.handler.convert.JpaJsonToMapConverter;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 定时任务定义表
 * @author 万宁
 * @version 2.0.0
 * @date 2021-07-12
 */
@Entity
@Table(schema = "public", name = "ss_schedule_task_definition")
public class ScheduleTaskDefinition implements Serializable {
    private static final long serialVersionUID = 1220096610225692133L;

    /**
     * id
     */
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="schedule_task_definition_seq")
    @SequenceGenerator(sequenceName="ss_schedule_task_definition_seq", name="schedule_task_definition_seq", allocationSize = 1)
    private Long id;

    /**
     * 创建时间
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime createTime;

    /**
     * 创建定时任务的服务名称，例如order-service
     */
    @Column(columnDefinition = "varchar(100)")
    private String serviceName;

    /**
     * 定时任务执行后，调用方提供的回调接口Url
     */
    @Column(columnDefinition = "varchar(200)")
    private String callbackUrl;

    /**
     * 会员Id
     */
    @Column
    private Long memberId;

    /**
     * 会员角色Id
     */
    @Column
    private Long roleId;

    /**
     * 定时任务的参数，例如订单Id等
     */
    @Convert(converter = JpaJsonToLongListConverter.class)
    @Column(columnDefinition = "jsonb")
    private List<Long> dataIds;

    /**
     * 任务开始执行的时间
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime execDateTime;

    /**
     * 任务开始执行的时间，（Unix时间戳格式）
     */
    @Column
    private Long execTime;

    /**
     * 执行间隔时间（分钟）
     */
    @Column
    private Integer intervalMinutes;

    /**
     * 定时任务名称，使用UUID生成的Identity
     */
    @Column(columnDefinition = "varchar(100)")
    private String taskName;

    /**
     * 由调用方指定的定时任务分组，如果为空或Null，则为服务名称
     */
    @Column(columnDefinition = "varchar(100)")
    private String taskGroup;

    /**
     * 任务类型，定义在 ScheduleTaskTypeEnum 中
     */
    @Column
    private Integer taskType;

    /**
     * 定时任务的自定义属性
     */
    @Convert(converter = JpaJsonToMapConverter.class)
    @Column(columnDefinition = "jsonb")
    private Map<String, Object> taskAttributes;

    /**
     * 执行次数
     */
    @Column
    private Integer execCount;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public String getServiceName() {
        return serviceName;
    }

    public void setServiceName(String serviceName) {
        this.serviceName = serviceName;
    }

    public String getCallbackUrl() {
        return callbackUrl;
    }

    public void setCallbackUrl(String callbackUrl) {
        this.callbackUrl = callbackUrl;
    }

    public Long getMemberId() {
        return memberId;
    }

    public void setMemberId(Long memberId) {
        this.memberId = memberId;
    }

    public Long getRoleId() {
        return roleId;
    }

    public void setRoleId(Long roleId) {
        this.roleId = roleId;
    }

    public List<Long> getDataIds() {
        return dataIds;
    }

    public void setDataIds(List<Long> dataIds) {
        this.dataIds = dataIds;
    }

    public LocalDateTime getExecDateTime() {
        return execDateTime;
    }

    public void setExecDateTime(LocalDateTime execDateTime) {
        this.execDateTime = execDateTime;
    }

    public Long getExecTime() {
        return execTime;
    }

    public void setExecTime(Long execTime) {
        this.execTime = execTime;
    }

    public Integer getIntervalMinutes() {
        return intervalMinutes;
    }

    public void setIntervalMinutes(Integer intervalMinutes) {
        this.intervalMinutes = intervalMinutes;
    }

    public String getTaskName() {
        return taskName;
    }

    public void setTaskName(String taskName) {
        this.taskName = taskName;
    }

    public String getTaskGroup() {
        return taskGroup;
    }

    public void setTaskGroup(String taskGroup) {
        this.taskGroup = taskGroup;
    }

    public Integer getTaskType() {
        return taskType;
    }

    public void setTaskType(Integer taskType) {
        this.taskType = taskType;
    }

    public Map<String, Object> getTaskAttributes() {
        return taskAttributes;
    }

    public void setTaskAttributes(Map<String, Object> taskAttributes) {
        this.taskAttributes = taskAttributes;
    }

    public Integer getExecCount() {
        return execCount;
    }

    public void setExecCount(Integer execCount) {
        this.execCount = execCount;
    }
}
